import pytest
def _excel_column_to_index(column):
    """
    将 Excel 列名转换为对应的索引（从 0 开始）
    """
    index = 0
    for char in column:
        index = index * 26 + (ord(char) - ord('A') + 1)
    return index - 1


def sort_excel_columns(columns):
    """
    对 Excel 列名列表进行排序
    :param columns: 包含 Excel 列名的列表
    :return: 排序后的 Excel 列名列表
    """
    return sorted(columns, key=_excel_column_to_index)


def iterate_sorted_columns(column_dict, start_index=0, step=1):
    """
    对字典中按 Excel 列名排序后的键，按照指定起始位置和步长进行遍历
    :param column_dict: 键为 Excel 列名的字典
    :param start_index: 起始索引，默认为 0
    :param step: 步长，默认为 1
    """
    sorted_columns = sort_excel_columns(column_dict.keys())
    for i in range(start_index, len(sorted_columns), step):
        column = sorted_columns[i]
        value = column_dict[column]
        print(f"Column: {column}, Value: {value}")

@pytest.mark.parametrize("input_columns,expected", [
    ({"A": 1,"Z": 26,"AA": 27,"AB": 28,"AC": 29},["A","Z","AA","AB","AC"]),
    ({"C": 3,"B": 2,"A": 1},["A","B","C"]),
    ({"Z": 26,"Y": 25,"X": 24},["X","Y","Z"])
    ])
def test_sort_excel_columns(input_columns, expected):
    """测试Excel列名排序功能"""
    assert sort_excel_columns(input_columns) == expected


    """测试列名转索引"""
    assert _excel_column_to_index("A") == 0
    assert _excel_column_to_index("Z") == 25
    assert _excel_column_to_index("AA") == 26
    assert _excel_column_to_index("AB") == 27